﻿using GarminUploader.Connector;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GarminUploader
{
    [Serializable]
    public class ActivityConnectionDict
    {
        private Dictionary<DateTime, List<ConnectorType>> activityConnectionDict;

        public ActivityConnectionDict()
        {
            activityConnectionDict = new Dictionary<DateTime, List<ConnectorType>>();
        }

        public bool isActivityConnected(DateTime startTime, ConnectorType connectorType)
        {
            // Check the starttime exists
            if (activityConnectionDict.ContainsKey(startTime))
            {
                // Check if the connector exist
                return activityConnectionDict[startTime].Contains(connectorType);
            }
            else
            {
                return false;
            }
        }

        public void addConnection(DateTime startTime, ConnectorType connectorType)
        {
            // First check if there is an entry for startTime
            if (activityConnectionDict.ContainsKey(startTime))
            {
                // Add to the existing entry
                activityConnectionDict[startTime].Add(connectorType);
            }
            else
            {
                // Create a new entry
                activityConnectionDict.Add(startTime, new List<ConnectorType> { connectorType });
            }
        }

        public List<DateTime> getStartTimes()
        {
            return activityConnectionDict.Keys.ToList();
        }

        public List<ConnectorType> getConnectors(DateTime startTime)
        {
            // First check if there is an entry for startTime
            if (activityConnectionDict.ContainsKey(startTime))
            {
                return activityConnectionDict[startTime];
            }
            else
            {
                // Else return an empty list
                return new List<ConnectorType>();
            }
        }

        public int getActivityCount()
        {
            return activityConnectionDict.Count;
        }
    }
}
